package com.office.web.controller.system;

import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.office.common.annotation.Log;
import com.office.common.core.controller.BaseController;
import com.office.common.core.domain.AjaxResult;
import com.office.common.enums.BusinessType;
import com.office.system.domain.FinanceAccount;
import com.office.system.service.IFinanceAccountService;
import com.office.common.utils.poi.ExcelUtil;
import com.office.common.core.page.TableDataInfo;

/**
 * 财务账户Controller
 * 
 * @author 数字牧马人
 */
@RestController
@RequestMapping("/system/finance/account")
public class FinanceAccountController extends BaseController
{
    @Autowired
    private IFinanceAccountService financeAccountService;

    /**
     * 查询财务账户列表
     */
    @PreAuthorize("@ss.hasPermi('system:finance:account:list')")
    @GetMapping("/list")
    public TableDataInfo list(FinanceAccount financeAccount)
    {
        startPage();
        List<FinanceAccount> list = financeAccountService.selectFinanceAccountList(financeAccount);
        return getDataTable(list);
    }

    /**
     * 导出财务账户列表
     */
    @PreAuthorize("@ss.hasPermi('system:finance:account:export')")
    @Log(title = "财务账户", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FinanceAccount financeAccount)
    {
        List<FinanceAccount> list = financeAccountService.selectFinanceAccountList(financeAccount);
        ExcelUtil<FinanceAccount> util = new ExcelUtil<FinanceAccount>(FinanceAccount.class);
        util.exportExcel(response, list, "财务账户数据");
    }

    /**
     * 获取财务账户详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:finance:account:query')")
    @GetMapping(value = "/{accountId}")
    public AjaxResult getInfo(@PathVariable("accountId") Long accountId)
    {
        return success(financeAccountService.selectFinanceAccountByAccountId(accountId));
    }

    /**
     * 新增财务账户
     */
    @PreAuthorize("@ss.hasPermi('system:finance:account:add')")
    @Log(title = "财务账户", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FinanceAccount financeAccount)
    {
        return toAjax(financeAccountService.insertFinanceAccount(financeAccount));
    }

    /**
     * 修改财务账户
     */
    @PreAuthorize("@ss.hasPermi('system:finance:account:edit')")
    @Log(title = "财务账户", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FinanceAccount financeAccount)
    {
        return toAjax(financeAccountService.updateFinanceAccount(financeAccount));
    }

    /**
     * 删除财务账户
     */
    @PreAuthorize("@ss.hasPermi('system:finance:account:remove')")
    @Log(title = "财务账户", businessType = BusinessType.DELETE)
	@DeleteMapping("/{accountIds}")
    public AjaxResult remove(@PathVariable Long[] accountIds)
    {
        return toAjax(financeAccountService.deleteFinanceAccountByAccountIds(accountIds));
    }
} 